<%-- 
    Document   : viewProduct
    Created on : Apr 6, 2011, 11:36:15 PM
    Author     : Nguyen Hung
--%>

<%@page import="java.text.NumberFormat"%>
<%@page import="Business.Product"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="Model.DAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%@include file="../WEB-INF/jspf/headeradmin.jspf" %>
        <style type="text/css" title="currentStyle">
            @import "datatable/demo_page.css";
            @import "datatable/demo_table_jui.css";
            @import "datatable/jquery-ui-1.8.4.custom.css";
        </style>
        
      	

        <script type="text/javascript" language="javascript" src="datatable/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="datatable/jquery.dataTables.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                oTable = $('#productTable').dataTable({
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers"
                });
            } );
            
            
            
            $(".confirm").easyconfirm();
            
            function xacnhan()
    {
        return confirm('Bạn thực sự muốn xóa Sản Phẩm này?');
    }
        </script>


    

    <%
                NumberFormat nf = NumberFormat.getInstance();
                //nf.setMinimumFractionDigits(2);
                nf.setMaximumFractionDigits(2);
                Connection connection = DAO.getConnection();
                String sql = "select productCode, image, vendorname, quantity, price "
                        + "from product, vendor where product.vendorid = vendor.vendorid and quantity >= 0";
                PreparedStatement prepareStatement = connection.prepareStatement(sql);
                ResultSet rs = prepareStatement.executeQuery();
                ArrayList<Product> products = new ArrayList<Product>();
                Product product;
                while (rs.next()) {
                    product = new Product();
                    product.setProductCode(rs.getString("productCode"));
                    product.setImage(rs.getString("image"));
                    product.setVendor(rs.getString("vendorname"));
                    product.setQuantity(rs.getInt("quantity"));
                    product.setPrice(rs.getDouble("price"));
                    products.add(product);
                }
                rs.close();
    %>
    <a href="addProduct.jsp">Thêm Sản Phẩm</a>

    <body>

        <table cellpadding="0" cellspacing="0" border="0" class="display" id="productTable">

            <thead>
                <tr>
                    <th>Mã sản phẩm</th>
                    <th>Hình ảnh</th>
                    <th>Nhà sản xuất</th>
                    <th>Số lượng </th>
                    <th>Giá</th>
                    <th>Xóa</th>
                </tr>
            </thead>
            <tbody>
                <%
                            for (Product p : products) {

                %>
                <tr class="gradeA">
                    <td><a href="EditProductInfomation?productCode=<%=p.getProductCode()%>"><%=p.getProductCode()%></a></td>
                    <td class ="center"><img src ="<%="../" + p.getImage()%>" width="50" height="45"></td>
                    <td><%=p.getVendor()%></td>
                    <td class="center"><%=p.getQuantity()%></td>
                    <td><%=nf.format(p.getPrice())%> VND</td>
                    <td class="center">

                        <!--<form action="DeleteProduct">
                            <input type="hidden" name="productCode" value="<%=p.getProductCode()%>">
                            <input type="image" src="http://localhost:8080/LaptopShop/images/design/button_delete.png" width="30" height="25">
                        </form>
                        !-->
                        <a  class="confirm" href="DeleteProduct?productCode=<%=p.getProductCode()%>" onclick="return xacnhan()" >Xóa sản phẩm</a>
                    </td>

                    <%
                                }
                    %>
                </tr>


            </tbody>






        </table>

 <%@include file="../WEB-INF/jspf/footeradmin.jspf" %>